import request from '@/utils/request'
import { getToken } from '@/utils/auth'

export function addAgentAudit(consoleUser) {
  return request({
    url: '/AgentAudit/',
    method: 'post',
    data: {
      username: consoleUser.username,
      password: '88888888',
      userGroup: 2,
      realname: consoleUser.realname,
      userPhone: consoleUser.userPhone,
      state: 0,
      accountId: consoleUser.accountId,
      accountName: consoleUser.accountName,
      bankName: consoleUser.bankName,
      education: consoleUser.education,
      email: consoleUser.email,
      file: consoleUser.file,
      idcard: consoleUser.idcard,
      level: 1,
      remarks: consoleUser.remarks,
      sex: consoleUser.sex,
      subordinateId: consoleUser.subordinateId,
      postUserId: getToken(),
      agentAuditOperation: 1,
      auditPostStatus: 0,
      agentLeader: 0
    }
  })
}

export function addAgentAuditConsoleUser(consoleUser) {
  return request({
    url: '/AgentAudit/',
    method: 'post',
    data: {
      username: consoleUser.username,
      password: '88888888',
      userGroup: 2,
      realname: consoleUser.realname,
      userPhone: consoleUser.userPhone,
      state: 0,
      accountId: consoleUser.accountId,
      accountName: consoleUser.accountName,
      bankName: consoleUser.bankName,
      education: consoleUser.education,
      email: consoleUser.email,
      file: consoleUser.file,
      idcard: consoleUser.idcard,
      level: 1,
      remarks: consoleUser.remarks,
      sex: consoleUser.sex,
      subordinateId: consoleUser.subordinateId,
      postUserId: getToken(),
      agentAuditOperation: 1,
      auditPostStatus: 0,
      agentLeader: 0
    }
  })
}

export function deleteAgent(consoleUser) {
  return request({
    url: '/AgentAudit/',
    method: 'post',
    data: {
      username: consoleUser.username,
      password: consoleUser.password,
      userGroup: 2,
      realname: consoleUser.realname,
      userPhone: consoleUser.userPhone,
      state: consoleUser.state,
      accountId: consoleUser.accountId,
      accountName: consoleUser.accountName,
      bankName: consoleUser.bankName,
      education: consoleUser.education,
      email: consoleUser.email,
      file: consoleUser.file,
      idcard: consoleUser.idcard,
      level: consoleUser.level,
      remarks: consoleUser.remarks,
      sex: consoleUser.sex,
      subordinateId: consoleUser.subordinateId,
      postUserId: getToken(),
      userId: consoleUser.userId,
      agentAuditOperation: 0,
      auditPostStatus: 1,
      agentLeader: consoleUser.agentLeader
    }
  })
}

export function updateAgent(consoleUser) {
  return request({
    url: '/AgentAudit/id',
    method: 'put',
    params: {
      agentAuditId: consoleUser.agentAuditId,
      username: consoleUser.username,
      password: consoleUser.password,
      userGroup: 2,
      realname: consoleUser.realname,
      userPhone: consoleUser.userPhone,
      state: consoleUser.state,
      accountId: consoleUser.accountId,
      accountName: consoleUser.accountName,
      bankName: consoleUser.bankName,
      education: consoleUser.education,
      email: consoleUser.email,
      file: consoleUser.file,
      idcard: consoleUser.idcard,
      level: consoleUser.level,
      remarks: consoleUser.remarks,
      sex: consoleUser.sex,
      subordinateId: consoleUser.subordinateId,
      postUserId: getToken(),
      userId: consoleUser.userId,
      agentAuditOperation: consoleUser.agentAuditOperation,
      auditPostStatus: consoleUser.auditPostStatus,
      agentLeader: consoleUser.agentLeader
    }
  })
}

export function getAllAgentAudit() {
  return request({
    url: '/AgentAudit/all',
    method: 'get'
  })
}

export function getAllPostedAgentAudit() {
  return request({
    url: '/AgentAudit/all',
    method: 'get'
  })
}

export function getAllAgentAuditByUserId() {
  return request({
    url: '/AgentAudit/selectByPostUserId',
    method: 'get',
    params: {
      postUserId: getToken()
    }
  })
}

export function getAllNoPosted() {
  return request({
    url: '/AgentAudit/selectByPostUserIdAndAuditPostStatus',
    method: 'get',
    params: {
      auditPostStatus: 0,
      postUserId: getToken()
    }
  })
}

export function getAgentAuditById(id) {
  return request({
    url: '/AgentAudit/id',
    method: 'get',
    params: {
      id: id
    }
  })
}

export function updateStatus(id, status, rejectionReason) {
  return request({
    url: '/AgentAudit/updateStatus',
    method: 'put',
    params: {
      Auditstatus: status,
      agentAuditId: id,
      agentAuditUserId: getToken(),
      rejectionReason: rejectionReason
    }
  })
}

export function updateAuditPostStatus(id, status) {
  return request({
    url: '/AgentAudit/updateAuditPostStatusByAgentAuditId',
    method: 'put',
    params: {
      agentAuditId: id,
      updatedAuditPostStatus: status
    }
  })
}
export function searchAgentAudit(search) {
  return request({
    url: '/AgentAudit/mohuSearch',
    method: 'get',
    params: {
      str: search.realName
    }
  })
}

export function searchByPostUserId(name) {
  return request({
    url: '/AgentAudit/mohuSearch',
    method: 'get',
    params: {
      postUserId: getToken(),
      str: name
    }
  })
}
